<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Rag Hu
 * Created Time: 2019/7/2 14:07
 * Modified Time: 2019/7/2 14:07
 * Version: 2.0
 */

namespace App\Modules\Inventory\Validators;


use Flower\Core\Repository\Contracts\ValidatorInterface;
use Flower\Core\Repository\Validator\LaravelValidator;

class GoodsValidator extends LaravelValidator
{
    protected $rules = [
        ValidatorInterface::RULE_CREATE => [
            'store_id' => 'required|numeric',
            'cat_id' => 'required|numeric',
            'name' => 'required|between:1,20',
            'image' => 'required',
            'small_name' => 'between:0,7',
            'buying_price' => 'required|numeric|min:0.01|max:99999',
            'market_price' => 'required_if:is_sell,1|numeric|min:0.01|max:99999',
            'royalty' => 'required_if:is_sell,1|numeric|min:0|max:100',
            'is_sell' => 'required|numeric',
            'specs' => 'required',
            'volume' => 'required'
        ],
        ValidatorInterface::RULE_UPDATE => [
            'cat_id' => 'filled|numeric',
            'name' => 'filled|between:1,20',
            'image' => 'filled',
            'small_name' => 'between:0,7',
            'buying_price' => 'filled|numeric|min:0.01|max:99999',
            'market_price' => 'required_if:is_sell,1|numeric|min:0.01|max:99999',
            'royalty' => 'required_if:is_sell,1|numeric|min:0|max:100',
            'is_sell' => 'filled|numeric',
            'specs' => 'filled',
            'volume' => 'filled'
        ]
    ];
    protected $messages = [
        'store_id.required' => '缺少店铺id',
        'store_id.numeric' => '店铺id格式错误',

        'cat_id.required' => '请选择分类id',
        'cat_id.numeric' => '分类id格式错误',

        'image.required' => '请上传商品图片',

        'name.required' => '请填写商品标题',
        'name.between' => '商品标题最多只能填写20个字符',

        'small_name.required' => '请填写商品短标题',
        'small_name.between' => '商品短标题最多只能填写7个字符',

        'buying_price.required' => '请填写进货价',
        'buying_price.max' => '进货价最多为99999',

        'market_price.required_if' => '请填写销售价',
        'market_price.max' => '销售价最多为99999',

        'royalty.required_if' => '请填写提成',
        'royalty.max' => '提成最多为99999',

        'specs.required' => '请填写规格',

        'volume.required' => '请填写容量',


    ];
}